home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: Dec, 2002
- //
- //<doc>
- //<name setConstraintRestPosition>
- //<owner "Alias|Wavefront Unsupported">
- //
- //<synopsis>
- // setConstraintRestPosition
- //
- //<returns>
- // None
- //
- //<description>
- // Script for setting the rest position of a constrained object.
- //
- //<examples>
- // The rest position is where a constrained object goes to when
- // the constraint is disabled (i.e. all weights equal zero).
- //
- // Say you have a cup constrained to a skeleton. At frame 10, you
- // want the skeleton to set the object on the table, where it will remain.
- // Go to frame 10, select the cup and call this method to set the
- // rest position.
- //
- // The constraint can now be disabled by setting its weight to 0,
- // and the cup will stay at its rest position.
- //
- //</doc>
- /////////////////////////////////////////////////////////////////////////
-
- global proc setConstraintRestPosition()
- {
- string $sels[] = `ls -sl`;
-
- int $counter = 0;
- string $constrainAttr = ".rotate";
- string $restAttr = ".restRotate";
-
- for ($constrainedObj in $sels) {
- // Find the constraint
- //
- string $constraint;
- string $p1 = `pointConstraint -q $constrainedObj`;
- string $a1 = `aimConstraint -q $constrainedObj`;
- string $o1 = `orientConstraint -q $constrainedObj`;
- string $s1 = `scaleConstraint -q $constrainedObj`;
- string $t1 = `tangentConstraint -q $constrainedObj`;
- string $n1 = `normalConstraint -q $constrainedObj`;
- string $par = `parentConstraint -q $constrainedObj`;
- if (size($p1)) {
- $constraint = $p1;
- $constrainAttr = ".translate";
- $restAttr = ".restTranslate";
- } else if (size($a1)) {
- $constraint = $a1;
- } else if (size($o1)) {
- $constraint = $o1;
- } else if (size($s1)) {
- $constrainAttr = ".scale";
- $restAttr = ".restScale";
- $constraint = $s1;
- } else if (size($t1)) {
- $constraint = $t1;
- } else if (size($n1)) {
- $constraint = $n1;
- }
-
- if (size($constraint)) {
- float $currVal[] = `getAttr ($constrainedObj+$constrainAttr)`;
- string $cmd = ("setAttr " + $constraint+$restAttr + " ");
- $cmd += ($currVal[0] + " " + $currVal[1] + " " + $currVal[2]);
- evalEcho $cmd;
- setAttr ($constrainedObj+$constrainAttr) $currVal[0] $currVal[1] $currVal[2];
- $counter++;
- } else if (size($par)) {
- float $currPos[] = `getAttr ($constrainedObj+".translate")`;
- float $currRot[] = `getAttr ($constrainedObj+".rotate")`;
- string $cmd = ("setAttr "+$par+".restTranslate ");
- $cmd += ($currPos[0] + " " + $currPos[1] + " " + $currPos[2]);
- evalEcho $cmd;
- string $cmd = ("setAttr "+$par+".restRotate ");
- $cmd += ($currRot[0] + " " + $currRot[1] + " " + $currRot[2]);
- evalEcho $cmd;
- setAttr ($constrainedObj+".translate") $currPos[0] $currPos[1] $currPos[2];
- setAttr ($constrainedObj+".rotate") $currRot[0] $currRot[1] $currRot[2];
- $counter++;
- }
- }
- if (0 == $counter) {
- error("A constrained object must be selected.");
- }
- }
-